﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace Gmantis.Controls
{
    [TemplateVisualState(Name = "Opened", GroupName = "DropDownOpenStates"), TemplateVisualState(Name = "Normal", GroupName = "CommonStates"), TemplateVisualState(Name = "Valid", GroupName = "ValidationStatesStates"), TemplateVisualState(Name = "InvalidUnfocused", GroupName = "ValidationStatesStates"), TemplateVisualState(Name = "InvalidFocused", GroupName = "ValidationStatesStates"), StyleTypedProperty(Property = "ValidationDecoratorStyle", StyleTargetType = typeof(ValidationDecorator)), TemplateVisualState(Name = "Focused", GroupName = "FocusStates"), TemplateVisualState(Name = "Unfocused", GroupName = "FocusStates"), TemplatePart(Name = "ArrowToggle", Type = typeof(ToggleButton)), TemplatePart(Name = "DropDownPopup", Type = typeof(Popup)), TemplateVisualState(Name = "Closed", GroupName = "DropDownOpenStates"), TemplateVisualState(Name = "MouseOver", GroupName = "CommonStates"), TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")]
    public class DropDownButton : HeaderedContentControl
    {
        // Fields
        private Popup _autoClosePopup;
        private Canvas _canvas;
        internal ToggleButton _elementArrowToggle;
        internal Popup _elementDropDownPopup;
        internal bool _isLoaded;
        private bool _isToggling;
        private RelativePopupPresenter _relativePopupPresenter;
        private bool _throwIsDropDownOpenChanged;
        private bool _throwIsMouseOverChanged;
        internal const string ArrowToggleElementName = "ArrowToggle";
        public static readonly DependencyProperty AutoCloseProperty = DependencyProperty.Register("AutoClose", typeof(bool), typeof(DropDownButton), new PropertyMetadata(false));
        public static readonly DependencyProperty AutoSizeModeProperty = DependencyProperty.Register("AutoSizeMode", typeof(AutoSizeMode), typeof(DropDownButton), new PropertyMetadata(AutoSizeMode.GrowAndShrink));
        public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(DropDownButton), null);
        public static readonly DependencyProperty DropDownDirectionProperty = DependencyProperty.Register("DropDownDirection", typeof(DropDownDirection), typeof(DropDownButton), new PropertyMetadata(DropDownDirection.BelowOrAbove, new PropertyChangedCallback(DropDownButton.OnDropDownDirectionPropertyChanged)));
        public static readonly DependencyProperty DropDownHeightProperty = DependencyProperty.Register("DropDownHeight", typeof(double), typeof(DropDownButton), new PropertyMetadata(100.0));
        internal const string DropDownPopupElementName = "DropDownPopup";
        public static readonly DependencyProperty DropDownWidthProperty = DependencyProperty.Register("DropDownWidth", typeof(double), typeof(DropDownButton), new PropertyMetadata(100.0));
        public static readonly DependencyProperty FocusBrushProperty = DependencyProperty.Register("FocusBrush", typeof(Brush), typeof(DropDownButton), null);
        internal static readonly DependencyProperty ForceMouseOverProperty = DependencyProperty.Register("ForceMouseOver", typeof(bool), typeof(DropDownButton), new PropertyMetadata(new PropertyChangedCallback(DropDownButton.OnForceMouseOverPropertyChanged)));
        public static readonly DependencyProperty IsDropDownOpenProperty = DependencyProperty.Register("IsDropDownOpen", typeof(bool), typeof(DropDownButton), new PropertyMetadata(false, new PropertyChangedCallback(DropDownButton.OnIsDropDownOpenPropertyChanged)));
        public static readonly DependencyProperty IsFocusedProperty = DependencyProperty.Register("IsFocused", typeof(bool), typeof(DropDownButton), new PropertyMetadata(new PropertyChangedCallback(DropDownButton.OnIsFocusedPropertyChanged)));
        public static readonly DependencyProperty IsMouseOverProperty = DependencyProperty.Register("IsMouseOver", typeof(bool), typeof(DropDownButton), new PropertyMetadata(new PropertyChangedCallback(DropDownButton.OnIsMouseOverPropertyChanged)));
        public static readonly DependencyProperty MaxDropDownHeightProperty = DependencyProperty.Register("MaxDropDownHeight", typeof(double), typeof(DropDownButton), new PropertyMetadata(double.MaxValue));
        public static readonly DependencyProperty MaxDropDownWidthProperty = DependencyProperty.Register("MaxDropDownWidth", typeof(double), typeof(DropDownButton), new PropertyMetadata(double.MaxValue));
        public static readonly DependencyProperty MinDropDownHeightProperty = DependencyProperty.Register("MinDropDownHeight", typeof(double), typeof(DropDownButton), new PropertyMetadata(0.0));
        public static readonly DependencyProperty MinDropDownWidthProperty = DependencyProperty.Register("MinDropDownWidth", typeof(double), typeof(DropDownButton), new PropertyMetadata(0.0));
        public static readonly DependencyProperty MouseOverBrushProperty = DependencyProperty.Register("MouseOverBrush", typeof(Brush), typeof(DropDownButton), null);
        public static readonly DependencyProperty PressedBrushProperty = DependencyProperty.Register("PressedBrush", typeof(Brush), typeof(DropDownButton), null);
        public static readonly DependencyProperty ValidationDecoratorStyleProperty = DependencyProperty.Register("ValidationDecoratorStyle", typeof(Style), typeof(DropDownButton), null);

        // Events
        public event EventHandler<PropertyChangedEventArgs<bool>> IsDropDownOpenChanged;

        public event EventHandler<PropertyChangedEventArgs<bool>> IsMouseOverChanged;

        // Methods
        public DropDownButton()
        {
            RoutedEventHandler handler = null;
            DependencyPropertyChangedEventHandler handler2 = null;
            this._throwIsDropDownOpenChanged = true;
            this._throwIsMouseOverChanged = true;
            base.DefaultStyleKey = typeof(DropDownButton);
            if (handler == null)
            {
                handler = delegate(object param0, System.Windows.RoutedEventArgs param1)
                {
                    this.ChangeVisualStateDropDownOpen(false);
                    this.ChangeVisualStateCommon(false);
                    this.ChangeVisualStateFocus(false);
                };
            }
            base.Loaded += handler;
            if (handler2 == null)
            {
                handler2 = (s, a) => this.ChangeVisualStateCommon(true);
            }
            base.IsEnabledChanged += handler2;
            base.GotFocus += new RoutedEventHandler(this.Control_GotFocus);
            base.LostFocus += new RoutedEventHandler(this.Control_LostFocus);
            base.MouseEnter += new MouseEventHandler(this.Control_MouseEnter);
            base.MouseLeave += new MouseEventHandler(this.Control_MouseLeave);
            this.SetCustomDefaultValues();
        }

        private void _popup_Closed(object sender, EventArgs e)
        {
            if (!this._isToggling)
            {
                this.IsDropDownOpen = false;
            }
        }

        private void arrow_Checked(object sender, System.Windows.RoutedEventArgs e)
        {
            if (e.OriginalSource == this._elementArrowToggle)
            {
                this.arrow_Toggle(true);
            }
        }

        private void arrow_Toggle(bool open)
        {
            if (!this._isToggling)
            {
                this.IsDropDownOpen = open;
            }
        }

        private void arrow_Unchecked(object sender, System.Windows.RoutedEventArgs e)
        {
            if (e.OriginalSource == this._elementArrowToggle)
            {
                this.arrow_Toggle(false);
            }
        }

        private void Control_GotFocus(object sender, System.Windows.RoutedEventArgs e)
        {
            this.IsFocused = true;
        }

        private void Control_LostFocus(object sender, System.Windows.RoutedEventArgs e)
        {
            this.IsFocused = false;
        }

        private void Control_MouseEnter(object sender, MouseEventArgs e)
        {
            if (InputEventArgs.GetPointerType(e) == PointerDeviceType.Mouse)
            {
                this.IsMouseOver = true;
            }
        }

        private void Control_MouseLeave(object sender, MouseEventArgs e)
        {
            if (InputEventArgs.GetPointerType(e) == PointerDeviceType.Mouse)
            {
                this.IsMouseOver = false;
            }
        }

        private void canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if (this.AutoClose)
            {
                this._elementArrowToggle.IsChecked = false;
            }
        }

        protected void ChangeVisualStateCommon(bool useTransitions)
        {
            if (!base.IsEnabled)
            {
                VisualStateHelper.GoToState(this, "Disabled", useTransitions);
            }
            if (base.IsEnabled)
            {
                VisualStateHelper.GoToState(this, "MouseOver", useTransitions);
            }
            if ((base.IsEnabled && !this.IsMouseOver) && !this.ForceMouseOver)
            {
                VisualStateHelper.GoToState(this, "Normal", useTransitions);
            }
        }

        protected void ChangeVisualStateDropDownOpen(bool useTransitions)
        {
            if (!this.IsDropDownOpen)
            {
                VisualStateHelper.GoToState(this, "Closed", useTransitions);
            }
            if (this.IsDropDownOpen)
            {
                VisualStateHelper.GoToState(this, "Opened", useTransitions);
            }
        }

        protected void ChangeVisualStateFocus(bool useTransitions)
        {
            if (!this.IsFocused)
            {
                VisualStateHelper.GoToState(this, "Unfocused", useTransitions);
            }
            if (this.IsFocused)
            {
                VisualStateHelper.GoToState(this, "Focused", useTransitions);
            }
        }

        protected virtual List<AnchorMatching> GetPreferedLocations()
        {
            List<AnchorMatching> list = new List<AnchorMatching>();
            switch (this.DropDownDirection)
            {
                case DropDownDirection.BelowOrAbove:
                    {
                        AnchorMatching item = new AnchorMatching
                        {
                            FixedElementAnchor = Anchor.BottomLeft,
                            MoveableElementAnchor = Anchor.TopLeft
                        };
                        list.Add(item);
                        AnchorMatching matching8 = new AnchorMatching
                        {
                            FixedElementAnchor = Anchor.BottomRight,
                            MoveableElementAnchor = Anchor.TopRight
                        };
                        list.Add(matching8);
                        AnchorMatching matching9 = new AnchorMatching
                        {
                            FixedElementAnchor = Anchor.TopLeft,
                            MoveableElementAnchor = Anchor.BottomLeft
                        };
                        list.Add(matching9);
                        AnchorMatching matching10 = new AnchorMatching
                        {
                            FixedElementAnchor = Anchor.TopRight,
                            MoveableElementAnchor = Anchor.BottomRight
                        };
                        list.Add(matching10);
                        break;
                    }
                case DropDownDirection.AboveOrBelow:
                    {
                        AnchorMatching matching = new AnchorMatching
                        {
                            FixedElementAnchor = Anchor.TopLeft,
                            MoveableElementAnchor = Anchor.BottomLeft
                        };
                        list.Add(matching);
                        AnchorMatching matching2 = new AnchorMatching
                        {
                            FixedElementAnchor = Anchor.TopRight,
                            MoveableElementAnchor = Anchor.BottomRight
                        };
                        list.Add(matching2);
                        AnchorMatching matching3 = new AnchorMatching
                        {
                            FixedElementAnchor = Anchor.BottomLeft,
                            MoveableElementAnchor = Anchor.TopLeft
                        };
                        list.Add(matching3);
                        AnchorMatching matching4 = new AnchorMatching
                        {
                            FixedElementAnchor = Anchor.BottomRight,
                            MoveableElementAnchor = Anchor.TopRight
                        };
                        list.Add(matching4);
                        break;
                    }
                case DropDownDirection.ForceBelow:
                    {
                        AnchorMatching matching11 = new AnchorMatching
                        {
                            FixedElementAnchor = Anchor.BottomLeft,
                            MoveableElementAnchor = Anchor.TopLeft
                        };
                        list.Add(matching11);
                        AnchorMatching matching12 = new AnchorMatching
                        {
                            FixedElementAnchor = Anchor.BottomRight,
                            MoveableElementAnchor = Anchor.TopRight
                        };
                        list.Add(matching12);
                        break;
                    }
                case DropDownDirection.ForceAbove:
                    {
                        AnchorMatching matching5 = new AnchorMatching
                        {
                            FixedElementAnchor = Anchor.TopLeft,
                            MoveableElementAnchor = Anchor.BottomLeft
                        };
                        list.Add(matching5);
                        AnchorMatching matching6 = new AnchorMatching
                        {
                            FixedElementAnchor = Anchor.TopRight,
                            MoveableElementAnchor = Anchor.BottomRight
                        };
                        list.Add(matching6);
                        break;
                    }
            }
            if (list.Count > 0)
            {
                list.Add(list[0]);
            }
            return list;
        }

        private T GetTemplateChild<T>(string childName, bool required, ref string errors) where T : class
        {
            DependencyObject templateChild = base.GetTemplateChild(childName);
            ApplyTemplateHelper.VerifyTemplateChild(typeof(T), "template part", childName, templateChild, required, ref errors);
            return (templateChild as T);
        }

        private static Storyboard GetTemplateChildResource(FrameworkElement root, string resourceName, bool required, ref string errors)
        {
            return GetTemplateChildResource<Storyboard>(root, resourceName, required, ref errors);
        }

        private static T GetTemplateChildResource<T>(FrameworkElement root, string resourceName, bool required, ref string errors) where T : class
        {
            object child = root.Resources[resourceName];
            ApplyTemplateHelper.VerifyTemplateChild(typeof(T), "resource", resourceName, child, required, ref errors);
            return (child as T);
        }

        private void HideAutoClosePopup()
        {
            this._autoClosePopup.IsOpen = false;
            FrameworkElement element = this.GetRootVisual() as FrameworkElement;
            this._canvas.MouseLeftButtonDown -= new MouseButtonEventHandler(this.canvas_MouseLeftButtonDown);
            element.SizeChanged -= new SizeChangedEventHandler(this.updateAutoClosePopupSize);
        }

        private void InitializeArrowTogglePart()
        {
            this._elementArrowToggle.IsThreeState = false;
            this._elementArrowToggle.IsChecked = false;
            this._elementArrowToggle.Checked += new RoutedEventHandler(this.arrow_Checked);
            this._elementArrowToggle.Unchecked += new RoutedEventHandler(this.arrow_Unchecked);
        }

        private void InitializeAutoClosePopup()
        {
            if (this._autoClosePopup == null)
            {
                Canvas canvas = new Canvas
                {
                    Background = new SolidColorBrush(Colors.Transparent)
                };
                this._canvas = canvas;
                FrameworkElement element = this.GetRootVisual() as FrameworkElement;
                this._canvas.Width = element.ActualWidth;
                this._canvas.Height = element.ActualHeight;
                this._canvas.SetBinding(UIElement.IsHitTestVisibleProperty, new Binding().From<DropDownButton>(this, x => x.AutoClose));
                this._autoClosePopup = new Popup();
                this._autoClosePopup.Child = this._canvas;
            }
        }

        private void InitializeDropDownPopupPart()
        {
            UIElement child = this._elementDropDownPopup.Child;
            this._elementDropDownPopup.Child = null;
            RelativePopupPresenter presenter = new RelativePopupPresenter
            {
                Content = child
            };
            this._relativePopupPresenter = presenter;
            //if (this.DropDownHeight == 0.0)
            //    this.DropDownHeight = this._elementHeaderPresenter.Height;
            //if (this.DropDownWidth == 0.0)
            //    this.DropDownWidth = this._elementHeaderPresenter.Width;
            this._relativePopupPresenter.SetBinding<DropDownButton>(RelativePopupPresenter.AutoSizeModeProperty, this, x => x.AutoSizeMode);
            this._elementDropDownPopup.Child = this._relativePopupPresenter;
            this._elementDropDownPopup.Closed += new EventHandler(this._popup_Closed);
            this.InitializeAutoClosePopup();
            this._elementDropDownPopup.MakeRelative(this, new Func<List<AnchorMatching>>(this.GetPreferedLocations));
        }

        private void OnAfterApplyTemplate()
        {
            this.BeginInvoke(() => this.UpdateIsDropDownOpen());
        }

        public override void OnApplyTemplate()
        {
            string errors = string.Empty;
            base.OnApplyTemplate();
            this._isLoaded = true;
            this._elementArrowToggle = this.GetTemplateChild<ToggleButton>("ArrowToggle", true, ref errors);
            if (this._elementArrowToggle != null)
            {
                this.InitializeArrowTogglePart();
            }
            this._elementDropDownPopup = this.GetTemplateChild<Popup>("DropDownPopup", true, ref errors);
            if (this._elementDropDownPopup != null)
            {
                this.InitializeDropDownPopupPart();
            }
            if (!string.IsNullOrEmpty(errors))
            {
                this._isLoaded = false;
                if ((base.Template != null) && !PlatformIndependent.IsInDesignMode(this))
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Template cannot be applied to DropDownButton.\nDetails: {0}", new object[] { errors }));
                }
            }
            else
            {
                this.ChangeVisualStateDropDownOpen(false);
                this.ChangeVisualStateCommon(false);
                this.ChangeVisualStateFocus(false);
                this.OnAfterApplyTemplate();
            }
        }

        private void OnDropDownDirectionChanged(DropDownDirection oldValue)
        {
        }

        private static void OnDropDownDirectionPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DropDownButton button = d as DropDownButton;
            DropDownDirection oldValue = (DropDownDirection)e.OldValue;
            button.OnDropDownDirectionChanged(oldValue);
        }

        private static void OnForceMouseOverPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            (d as DropDownButton).ChangeVisualStateCommon(true);
        }

        private void OnIsDropDownOpenChanged(bool oldValue)
        {
            if (this.IsDropDownOpen && (this._relativePopupPresenter != null))
            {
                this._relativePopupPresenter.InvalidateAutoSize();
            }
            this.UpdateIsDropDownOpen();
        }

        private static void OnIsDropDownOpenPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DropDownButton sender = d as DropDownButton;
            bool oldValue = (bool)e.OldValue;
            sender.OnIsDropDownOpenChanged(oldValue);
            if ((sender.IsDropDownOpenChanged != null) && sender._throwIsDropDownOpenChanged)
            {
                PropertyChangedEventArgs<bool> args = new PropertyChangedEventArgs<bool>
                {
                    OldValue = (bool)e.OldValue,
                    NewValue = (bool)e.NewValue
                };
                sender.IsDropDownOpenChanged(sender, args);
            }
            sender.ChangeVisualStateDropDownOpen(true);
        }

        private static void OnIsFocusedPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            (d as DropDownButton).ChangeVisualStateFocus(true);
        }

        private static void OnIsMouseOverPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            DropDownButton sender = d as DropDownButton;
            if ((sender.IsMouseOverChanged != null) && sender._throwIsMouseOverChanged)
            {
                PropertyChangedEventArgs<bool> args = new PropertyChangedEventArgs<bool>
                {
                    OldValue = (bool)e.OldValue,
                    NewValue = (bool)e.NewValue
                };
                sender.IsMouseOverChanged(sender, args);
            }
            sender.ChangeVisualStateCommon(true);
        }

        private void OnLoaded(object sender, System.Windows.RoutedEventArgs e)
        {
            if (this._elementDropDownPopup != null)
            {
                this._elementDropDownPopup.Child = this._relativePopupPresenter;
            }
        }

        private void OnUnloaded(object sender, System.Windows.RoutedEventArgs e)
        {
            if (this._elementDropDownPopup != null)
            {
                this._elementDropDownPopup.Child = null;
            }
        }

        private void SetCustomDefaultValues()
        {
            base.IsEnabled = true;
            base.IsTabStop = false;
            base.IsEnabledChanged += (param0, param1) => this.IsDropDownOpen = false;
            base.Loaded += new RoutedEventHandler(this.OnLoaded);
            base.Unloaded += new RoutedEventHandler(this.OnUnloaded);
        }

        private void ShowAutoClosePopup()
        {
            int num = (int)this._elementDropDownPopup.GetValue(Canvas.ZIndexProperty);
            this._autoClosePopup.SetValue(Canvas.ZIndexProperty, num - 1);
            this._autoClosePopup.IsOpen = true;
            this.updateAutoClosePopupSize(null, null);
            FrameworkElement element = this.GetRootVisual() as FrameworkElement;
            this._canvas.MouseLeftButtonDown += new MouseButtonEventHandler(this.canvas_MouseLeftButtonDown);
            element.SizeChanged += new SizeChangedEventHandler(this.updateAutoClosePopupSize);
        }

        private void updateAutoClosePopupSize(object sender, SizeChangedEventArgs e)
        {
            FrameworkElement element = this.GetRootVisual() as FrameworkElement;
            this._canvas.Width = element.ActualWidth;
            this._canvas.Height = element.ActualHeight;
        }

        private void UpdateIsDropDownOpen()
        {
            if (!base.IsEnabled)
            {
                this.IsDropDownOpen = false;
            }
            this._isToggling = true;
            if (this._isLoaded)
            {
                if (this.IsDropDownOpen && !PlatformIndependent.IsInDesignMode(this))
                {
                    this.ShowAutoClosePopup();
                    this._elementDropDownPopup.IsOpen = true;
                    this._elementArrowToggle.IsChecked = true;
                }
                else
                {
                    this.HideAutoClosePopup();
                    if (this._elementDropDownPopup != null)
                    {
                        this._elementDropDownPopup.IsOpen = false;
                    }
                    this._elementArrowToggle.IsChecked = false;
                }
            }
            this._isToggling = false;
        }

        // Properties
        public bool AutoClose
        {
            get { return (bool)GetValue(AutoCloseProperty); }
            set { SetValue(AutoCloseProperty, value); }
        }

        public AutoSizeMode AutoSizeMode
        {
            get { return (AutoSizeMode)GetValue(AutoSizeModeProperty); }
            set { SetValue(AutoSizeModeProperty, value); }
        }

        public CornerRadius CornerRadius
        {
            get { return (CornerRadius)GetValue(CornerRadiusProperty); }
            set { SetValue(CornerRadiusProperty, value); }
        }

        public DropDownDirection DropDownDirection
        {
            get { return (DropDownDirection)GetValue(DropDownDirectionProperty); }
            set { SetValue(DropDownDirectionProperty, value); }
        }

        public double DropDownHeight
        {
            get { return (double)GetValue(DropDownHeightProperty); }
            set { SetValue(DropDownHeightProperty, value); }
        }

        public double DropDownWidth
        {
            get { return (double)GetValue(DropDownWidthProperty); }
            set { SetValue(DropDownWidthProperty, value); }
        }

        public Brush FocusBrush
        {
            get { return (Brush)GetValue(FocusBrushProperty); }
            set { SetValue(FocusBrushProperty, value); }
        }

        internal bool ForceMouseOver
        {
            get { return (bool)GetValue(ForceMouseOverProperty); }
            set { SetValue(ForceMouseOverProperty, value); }
        }

        public bool IsDropDownOpen
        {
            get { return (bool)GetValue(IsDropDownOpenProperty); }
            set { SetValue(IsDropDownOpenProperty, value); }
        }

        public bool IsFocused
        {
            get { return (bool)GetValue(IsFocusedProperty); }
            set { SetValue(IsFocusedProperty, value); }
        }

        public bool IsMouseOver
        {
            get { return (bool)GetValue(IsMouseOverProperty);}
            internal set { SetValue(IsMouseOverProperty, value); }
        }

        public double MaxDropDownHeight
        {
            get { return (double)GetValue(MaxDropDownHeightProperty);}
            set { SetValue(MaxDropDownHeightProperty, value); }
        }

        public double MaxDropDownWidth
        {
            get { return (double)GetValue(MaxDropDownWidthProperty); }
            set { SetValue(MaxDropDownWidthProperty, value); }
        }

        public double MinDropDownHeight
        {
            get { return (double)GetValue(MinDropDownHeightProperty); }
            set { SetValue(MinDropDownHeightProperty, value); }
        }

        public double MinDropDownWidth
        {
            get { return (double)GetValue(MinDropDownWidthProperty); }
            set { SetValue(MinDropDownWidthProperty, value); }
        }

        public Brush MouseOverBrush
        {
            get { return (Brush)GetValue(MouseOverBrushProperty); }
            set { SetValue(MouseOverBrushProperty, value); }
        }

        public Brush PressedBrush
        {
            get { return (Brush)GetValue(PressedBrushProperty); }
            set { SetValue(PressedBrushProperty, value); }
        }

        public Style ValidationDecoratorStyle
        {
            get { return (Style)GetValue(ValidationDecoratorStyleProperty); }
            set { SetValue(ValidationDecoratorStyleProperty, value); }
        }
    }

    public enum AutoSizeMode
    {
        GrowAndShrink,
        GrowOnly,
        GrowHorizontally
    }

    public enum DropDownDirection
    {
        BelowOrAbove,
        AboveOrBelow,
        ForceBelow,
        ForceAbove
    }
}
